package com.dianping.localcache;

import java.text.DateFormat;
import java.util.Date;

public final class CacheInfo {
	public final String url;
	public final int size;
	public final long create;

	public CacheInfo(String url, int size, long create) {
		this.url = url;
		this.size = size;
		this.create = create;
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof CacheInfo) {
			if (o.hashCode() != hashCode())
				return false;
			CacheInfo c = (CacheInfo) o;
			return c.size == size && c.create == create && c.url.equals(url);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return url.hashCode() ^ (size << 16) ^ ((int) create);
	}

	private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance();

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Cache: ");
		sb.append("url=").append(url);
		sb.append(", size=").append(size);
		sb.append(", create=").append(DATE_FORMAT.format(new Date(create)));
		return sb.toString();
	}
}
